package com.athena.crm.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.athena.crm.domain.bo.CrmClueFollrecordsAddBo;
import com.athena.crm.domain.bo.CrmCustomerFollrecordsAddBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.athena.common.annotation.RepeatSubmit;
import com.athena.common.annotation.Log;
import com.athena.common.core.controller.BaseController;
import com.athena.common.core.domain.PageQuery;
import com.athena.common.core.domain.R;
import com.athena.common.core.validate.AddGroup;
import com.athena.common.core.validate.EditGroup;
import com.athena.common.core.validate.QueryGroup;
import com.athena.common.enums.BusinessType;
import com.athena.common.utils.poi.ExcelUtil;
import com.athena.crm.domain.vo.CrmCustomerFollrecordsVo;
import com.athena.crm.domain.bo.CrmCustomerFollrecordsBo;
import com.athena.crm.service.ICrmCustomerFollrecordsService;
import com.athena.common.core.page.TableDataInfo;

/**
 * 客户跟进记录
 *
 * @author ruoyi
 * @date 2023-09-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/crm/customerFollrecords")
public class CrmCustomerFollrecordsController extends BaseController {

    private final ICrmCustomerFollrecordsService iCrmCustomerFollrecordsService;

    /**
     * 查询客户跟进记录列表
     */
    @SaCheckPermission("crm:customerFollrecords:list")
    @GetMapping("/list")
    public TableDataInfo<CrmCustomerFollrecordsVo> list(CrmCustomerFollrecordsBo bo, PageQuery pageQuery) {
        return iCrmCustomerFollrecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出客户跟进记录列表
     */
    @SaCheckPermission("crm:customerFollrecords:export")
    @Log(title = "客户跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CrmCustomerFollrecordsBo bo, HttpServletResponse response) {
        List<CrmCustomerFollrecordsVo> list = iCrmCustomerFollrecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "客户跟进记录", CrmCustomerFollrecordsVo.class, response);
    }

    /**
     * 获取客户跟进记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("crm:customerFollrecords:query")
    @GetMapping("/{id}")
    public R<CrmCustomerFollrecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iCrmCustomerFollrecordsService.queryById(id));
    }

    /**
     * 新增客户跟进记录
     */
    @SaCheckPermission("crm:customerFollrecords:add")
    @Log(title = "客户跟进记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CrmCustomerFollrecordsBo bo) {
        return toAjax(iCrmCustomerFollrecordsService.insertByBo(bo));
    }

    /**
     * 新增客户跟进记录
     */
    @SaCheckPermission("crm:customerFollrecords:add")
    @Log(title = "客户跟进记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/addRecord")
    public R<Void> addRecord(@Validated(AddGroup.class) @RequestBody CrmCustomerFollrecordsAddBo bbo) {
        return toAjax(iCrmCustomerFollrecordsService.insertByBbo(bbo));
    }

    /**
     * 修改客户跟进记录
     */
    @SaCheckPermission("crm:customerFollrecords:edit")
    @Log(title = "客户跟进记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CrmCustomerFollrecordsBo bo) {
        return toAjax(iCrmCustomerFollrecordsService.updateByBo(bo));
    }

    /**
     * 删除客户跟进记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("crm:customerFollrecords:remove")
    @Log(title = "客户跟进记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iCrmCustomerFollrecordsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
